Skip to main content

RoleManager.sol

Git Source

Inherits: Governance2Step

State Variables​

name​

bytes32 internal constant _name_ = bytes32(abi.encodePacked("Yearn V3 Vault Role Manager"));

DADDY​

Position ID for "daddy".

bytes32 public constant DADDY = keccak256("Daddy");

BRAIN​

Position ID for "brain".

bytes32 public constant BRAIN = keccak256("Brain");

KEEPER​

Position ID for "keeper".

bytes32 public constant KEEPER = keccak256("Keeper");

SECURITY​

Position ID for "security".

bytes32 public constant SECURITY = keccak256("Security");

REGISTRY​

Position ID for the Registry.

bytes32 public constant REGISTRY = keccak256("Registry");

ACCOUNTANT​

Position ID for the Accountant.

bytes32 public constant ACCOUNTANT = keccak256("Accountant");

DEBT_ALLOCATOR​

Position ID for Debt Allocator

bytes32 public constant DEBT_ALLOCATOR = keccak256("Debt Allocator");

STRATEGY_MANAGER​

Position ID for Strategy manager.

bytes32 public constant STRATEGY_MANAGER = keccak256("Strategy Manager");

ALLOCATOR_FACTORY​

Position ID for the Allocator Factory.

bytes32 public constant ALLOCATOR_FACTORY = keccak256("Allocator Factory");

chad​

Immutable address that the RoleManager position

address public immutable chad;

vaults​

Array storing addresses of all managed vaults.

address[] public vaults;

defaultProfitMaxUnlock​

Default time until profits are fully unlocked for new vaults.

uint256 public defaultProfitMaxUnlock = 10 days;

_positions​

Mapping of position ID to position information.

mapping(bytes32 => Position) internal _positions;

vaultConfig​

Mapping of vault addresses to its config.

mapping(address => VaultConfig) public vaultConfig;

_assetToVault​

Mapping of underlying asset, api version and category to vault.

mapping(address => mapping(string => mapping(uint256 => address))) internal _assetToVault;

Functions​

onlyPositionHolder​

Only allow either governance or the position holder to call.

modifier onlyPositionHolder(bytes32 _positionId);

_isPositionHolder​

Check if the msg sender is governance or the specified position holder.

function _isPositionHolder(bytes32 _positionId) internal view virtual;

constructor​

constructor(
address _governance,
address _daddy,
address _brain,
address _security,
address _keeper,
address _strategyManager,
address _registry
) Governance2Step(_governance);

newVault​

Creates a new endorsed vault with default profit max unlock time and doesn't set the deposit limit.

function newVault(address _asset, uint256 _category) external virtual onlyPositionHolder(DADDY) returns (address);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.

Returns

NameTypeDescription
<none>address_vault Address of the newly created vault.

newVault​

Creates a new endorsed vault with default profit max unlock time.

function newVault(address _asset, uint256 _category, uint256 _depositLimit)
external
virtual
onlyPositionHolder(DADDY)
returns (address);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_depositLimituint256The deposit limit to start the vault with.

Returns

NameTypeDescription
<none>address_vault Address of the newly created vault.

newVault​

Creates a new endorsed vault.

function newVault(address _asset, uint256 _category, uint256 _depositLimit, uint256 _profitMaxUnlockTime)
external
virtual
onlyPositionHolder(DADDY)
returns (address);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_depositLimituint256The deposit limit to start the vault with.
_profitMaxUnlockTimeuint256Time until profits are fully unlocked.

Returns

NameTypeDescription
<none>address_vault Address of the newly created vault.

_newVault​

Creates a new endorsed vault.

function _newVault(address _asset, uint256 _category, uint256 _depositLimit, uint256 _profitMaxUnlockTime)
internal
virtual
returns (address _vault);

Parameters

NameTypeDescription
_assetaddressAddress of the underlying asset.
_categoryuint256Category of the vault.
_depositLimituint256The deposit limit to start the vault with.
_profitMaxUnlockTimeuint256Time until profits are fully unlocked.

Returns

NameTypeDescription
_vaultaddressAddress of the newly created vault.

_deployAllocator​

Deploys a debt allocator for the specified vault.

function _deployAllocator(address _vault) internal virtual returns (address _debtAllocator);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
_debtAllocatoraddressAddress of the deployed debt allocator.

_sanctify​

Assigns roles to the newly added vault. This will override any previously set roles for the holders. But not effect the roles held by other addresses.

function _sanctify(address _vault, address _debtAllocator) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to sanctify.
_debtAllocatoraddressAddress of the debt allocator for the vault.

_setRole​

Used internally to set the roles on a vault for a given position. Will not set the roles if the position holder is address(0). This does not check that the roles are !=0 because it is expected that the holder will be set to 0 if the position is not being used.

function _setRole(address _vault, Position memory _position) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.
_positionPositionHolder address and roles to set.

_setAccountant​

Sets the accountant on the vault and adds the vault to the accountant. This temporarily gives the ACCOUNTANT_MANAGER role to this contract.

function _setAccountant(address _vault) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to set up the accountant for.

_setDepositLimit​

Used to set an initial deposit limit when a new vault is deployed. Any further updates to the limit will need to be done by an address that holds the DEPOSIT_LIMIT_MANAGER role.

function _setDepositLimit(address _vault, uint256 _depositLimit) internal virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the newly deployed vault.
_depositLimituint256The deposit limit to set.

addNewVault​

Adds a new vault to the RoleManager with the specified category.

If not already endorsed this function will endorse the vault. A new debt allocator will be deployed and configured.

function addNewVault(address _vault, uint256 _category) external virtual;

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be added.
_categoryuint256Category associated with the vault.

addNewVault​

Adds a new vault to the RoleManager with the specified category and debt allocator.

If not already endorsed this function will endorse the vault.

function addNewVault(address _vault, uint256 _category, address _debtAllocator)
public
virtual
onlyPositionHolder(DADDY);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be added.
_categoryuint256Category associated with the vault.
_debtAllocatoraddressAddress of the debt allocator for the vault.

updateDebtAllocator​

Update a _vaults debt allocator.

This will deploy a new allocator using the current allocator factory set.

function updateDebtAllocator(address _vault) external virtual returns (address _newDebtAllocator);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the allocator for.

updateDebtAllocator​

Update a _vaults debt allocator to a specified _debtAllocator.

function updateDebtAllocator(address _vault, address _debtAllocator) public virtual onlyPositionHolder(BRAIN);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the allocator for.
_debtAllocatoraddressAddress of the new debt allocator.

updateKeeper​

Update a _vaults keeper to a specified _keeper.

function updateKeeper(address _vault, address _keeper) external virtual onlyPositionHolder(BRAIN);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to update the keeper for.
_keeperaddressAddress of the new keeper.

removeVault​

Removes a vault from the RoleManager.

This will NOT un-endorse the vault from the registry.

function removeVault(address _vault) external virtual onlyPositionHolder(BRAIN);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to be removed.

removeRoles​

Removes a specific role(s) for a _holder from the _vaults.

Can be used to remove one specific role or multiple.

function removeRoles(address[] calldata _vaults, address _holder, uint256 _role) external virtual onlyGovernance;

Parameters

NameTypeDescription
_vaultsaddress[]Array of vaults to adjust.
_holderaddressAddress who's having a role removed.
_roleuint256The role or roles to remove from the _holder.

setPositionRoles​

Setter function for updating a positions roles.

function setPositionRoles(bytes32 _position, uint256 _newRoles) external virtual onlyGovernance;

Parameters

NameTypeDescription
_positionbytes32Identifier for the position.
_newRolesuint256New roles for the position.

setPositionHolder​

Setter function for updating a positions holder.

function setPositionHolder(bytes32 _position, address _newHolder) external virtual onlyGovernance;

Parameters

NameTypeDescription
_positionbytes32Identifier for the position.
_newHolderaddressNew address for position.

setDefaultProfitMaxUnlock​

Sets the default time until profits are fully unlocked for new vaults.

function setDefaultProfitMaxUnlock(uint256 _newDefaultProfitMaxUnlock) external virtual onlyGovernance;

Parameters

NameTypeDescription
_newDefaultProfitMaxUnlockuint256New value for defaultProfitMaxUnlock.

name​

Get the name of this contract.

function name() external view virtual returns (string memory);

getAllVaults​

Get all vaults that this role manager controls..

function getAllVaults() external view virtual returns (address[] memory);

Returns

NameTypeDescription
<none>address[]The full array of vault addresses.

getVault​

Get the vault for a specific asset, api and category.

This will return address(0) if one has not been added or deployed.

function getVault(address _asset, string memory _apiVersion, uint256 _category)
external
view
virtual
returns (address);

Parameters

NameTypeDescription
_assetaddressThe underlying asset used.
_apiVersionstringThe version of the vault.
_categoryuint256The category of the vault.

Returns

NameTypeDescription
<none>addressThe vault for the specified _asset, _apiVersion and _category.

isVaultsRoleManager​

Check if a vault is managed by this contract.

This will check if the asset variable in the struct has been set for an easy external view check. Does not check the vaults role_manager position since that can be set by anyone for a random vault.

function isVaultsRoleManager(address _vault) external view virtual returns (bool);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault to check.

Returns

NameTypeDescription
<none>bool. The vaults role manager status.

getDebtAllocator​

Get the debt allocator for a specific vault.

Will return address(0) if the vault is not managed by this contract.

function getDebtAllocator(address _vault) external view virtual returns (address);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
<none>address. Address of the debt allocator if any.

getCategory​

Get the category for a specific vault.

Will return 0 if the vault is not managed by this contract.

function getCategory(address _vault) external view virtual returns (uint256);

Parameters

NameTypeDescription
_vaultaddressAddress of the vault.

Returns

NameTypeDescription
<none>uint256. The category of the vault if any.

getPosition​

Get the address and roles given to a specific position.

function getPosition(bytes32 _positionId) public view virtual returns (address, uint256);

Parameters

NameTypeDescription
_positionIdbytes32The position identifier.

Returns

NameTypeDescription
<none>addressThe address that holds that position.
<none>uint256The roles given to the specified position.

getPositionHolder​

Get the current address assigned to a specific position.

function getPositionHolder(bytes32 _positionId) public view virtual returns (address);

Parameters

NameTypeDescription
_positionIdbytes32The position identifier.

Returns

NameTypeDescription
<none>addressThe current address assigned to the specified position.

getPositionRoles​

Get the current roles given to a specific position ID.

function getPositionRoles(bytes32 _positionId) public view virtual returns (uint256);

Parameters

NameTypeDescription
_positionIdbytes32The position identifier.

Returns

NameTypeDescription
<none>uint256The current roles given to the specified position ID.

getDaddy​

Get the address assigned to the Daddy position.

function getDaddy() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Daddy position.

getBrain​

Get the address assigned to the Brain position.

function getBrain() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Brain position.

getSecurity​

Get the address assigned to the Security position.

function getSecurity() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Security position.

getKeeper​

Get the address assigned to the Keeper position.

function getKeeper() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Keeper position.

getStrategyManager​

Get the address assigned to the strategy manager.

function getStrategyManager() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the strategy manager.

getAccountant​

Get the address assigned to the accountant.

function getAccountant() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the accountant.

getRegistry​

Get the address assigned to the Registry.

function getRegistry() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the Registry.

getDebtAllocator​

Get the address assigned to be the debt allocator if any.

function getDebtAllocator() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to be the debt allocator if any.

getAllocatorFactory​

Get the address assigned to the allocator factory.

function getAllocatorFactory() external view virtual returns (address);

Returns

NameTypeDescription
<none>addressThe address assigned to the allocator factory.

getDaddyRoles​

Get the roles given to the Daddy position.

function getDaddyRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Daddy position.

getBrainRoles​

Get the roles given to the Brain position.

function getBrainRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Brain position.

getSecurityRoles​

Get the roles given to the Security position.

function getSecurityRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Security position.

getKeeperRoles​

Get the roles given to the Keeper position.

function getKeeperRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the Keeper position.

getDebtAllocatorRoles​

Get the roles given to the debt allocators.

function getDebtAllocatorRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the debt allocators.

getStrategyManagerRoles​

Get the roles given to the strategy manager.

function getStrategyManagerRoles() external view virtual returns (uint256);

Returns

NameTypeDescription
<none>uint256The roles given to the strategy manager.

Events​

AddedNewVault​

Emitted when a new vault has been deployed or added.

event AddedNewVault(address indexed vault, address indexed debtAllocator, uint256 category);

UpdateDebtAllocator​

Emitted when a vaults debt allocator is updated.

event UpdateDebtAllocator(address indexed vault, address indexed debtAllocator);

UpdatePositionHolder​

Emitted when a new address is set for a position.

event UpdatePositionHolder(bytes32 indexed position, address indexed newAddress);

RemovedVault​

Emitted when a vault is removed.

event RemovedVault(address indexed vault);

UpdatePositionRoles​

Emitted when a new set of roles is set for a position

event UpdatePositionRoles(bytes32 indexed position, uint256 newRoles);

UpdateDefaultProfitMaxUnlock​

Emitted when the defaultProfitMaxUnlock variable is updated.

event UpdateDefaultProfitMaxUnlock(uint256 newDefaultProfitMaxUnlock);

Errors​

AlreadyDeployed​

Revert message for when a vault has already been deployed.

error AlreadyDeployed(address _vault);

Structs​

Position​

Position struct

struct Position {
address holder;
uint96 roles;
}

VaultConfig​

Config that holds all vault info.

struct VaultConfig {
address asset;
uint256 category;
address debtAllocator;
uint256 index;
}